﻿/*
 * @Author: Song Xinxin
 * @Date: 2022-10-31 17:12:51
 * @LastEditors: Song Xinxin
 * @LastEditTime: 2022-11-07 12:49:16
 * @FilePath: \WYW_0419_Oasis\JavaScripts\Modules\Skill\Module_Skill.ts
 * @Description: 
 * 
 * Copyright (c) 2022 by error: git config user.name && git config user.email & please set dead value or install git, All Rights Reserved. 
 */
import { DataCenterS, ModuleC, ModuleS, UI } from "odin";
import { Consts } from "../../Consts";
import { UIGame } from "../../UI/UIGame";
import { Data_Skill } from "./Data_Skill";

export class ModuleS_Skill extends ModuleS<ModuleC_Skill,Data_Skill>
{

	/**
	 * 初始化玩家技能数据
	 */
	public initSkill():void
	{
		this.currentData.setShoot(false);
		this.currentData.setFly(false);
		this.currentData.setHide(false);
		this.currentData.setHide_Over(true);
		this.currentData.setFly_Over(true);
		this.currentData.saveData(true);
	}

	/**
	 * 隐身技能
	 */
	public HideSkill(player:GamePlay.Player):void
	{
		player.character.isVisible = false;
		setTimeout(()=>
		{
			player.character.isVisible = true;
		},Consts.SkillAttr.Hide.duration*1000)
	}

	/**
	 * 技能进入CD
	 * @param data 技能数据
	 */
	public Hide_CD(data:Data_Skill):void
	{
		data.setHide_Over(false);
		data.saveData(true);
		setTimeout(()=>
		{
			data.setHide_Over(true);
			data.saveData(true);
		},Consts.SkillAttr.Hide.CD*1000)
	}

	/**
	 * 使用隐身技能
	 */
	public net_useHide():void
	{
		if(this.currentData.getHide_over == true)
		{
			this.HideSkill(this.currentPlayer);
			this.Hide_CD(this.currentData);
			this.callClientFun(this.currentPlayer,this.client.net_hideCD());
		}
	}

	/**
	 * 飞行技能
	 * @param player 使用飞行技能的角色
	 */
	public FlySkill(player:GamePlay.Player):void
	{
		player.character.switchToFlying();
		setTimeout(()=>
		{
			player.character.switchToWalking();
			player.character.animationStance = Consts.HOLD_GUN_GUID;
		},Consts.SkillAttr.Fly.duration*1000)
	}

	/**
	 * 技能进入CD
	 * @param data 技能数据
	 */
	public Fly_CD(data:Data_Skill):void
	{
		data.setFly_Over(false);
		data.saveData(true);
		setTimeout(()=>
		{
			data.setFly_Over(true);
			data.saveData(true);
		},Consts.SkillAttr.Fly.CD*1000)
	}

	/**
	 * 使用飞行技能
	 */
	public net_useFly():void
	{
		if(this.currentData.getFly_over == true)
		{
			this.FlySkill(this.currentPlayer);
			this.Fly_CD(this.currentData);
			this.callClientFun(this.currentPlayer,this.client.net_flyCD());
		}
	}

	/**
	 * 解锁射击
	 * @param player 解锁射击的玩家 
	 */
	public UnlockShoot(player:GamePlay.Player):void
	{
		let skilldata = DataCenterS.instance.getModuleData(player,Data_Skill);
		if(skilldata.ShootState == false)
		{
			this.callClientFun(player,this.client.net_showShoot());
		}
		skilldata.setShoot(true);
		skilldata.saveData(true);
	}

	/**
	 * 解锁飞行技能
	 * @param player 解锁飞行技能的玩家 
	 */
	public UnlockFly(player:GamePlay.Player):void
	{
		let skilldata = DataCenterS.instance.getModuleData(player,Data_Skill);
		if(skilldata.FlyState == false)
		{
			this.callClientFun(player,this.client.net_showFly());
		}
		skilldata.setFly(true);
		skilldata.saveData(true);
	}

	/**
	 * 解锁隐身技能
	 * @param player 解锁隐身技能的玩家 
	 */
	public UnlockHide(player:GamePlay.Player):void
	{
		let skilldata = DataCenterS.instance.getModuleData(player,Data_Skill);
		if(skilldata.HideState == false)
		{
			this.callClientFun(player,this.client.net_showHide());
		}
		skilldata.setHide(true);
		skilldata.saveData(true);
	}
}

export class ModuleC_Skill extends ModuleC<ModuleS_Skill,Data_Skill>
{

	/**
	 * 使用隐身技能
	 */
	public useHide():void
	{
		this.server.net_useHide();
	}

	/**
	 * 使用飞行技能
	 */
	public useFly():void
	{
		this.server.net_useFly();
	}

	/**
	 * 显示射击UI
	 */
	public net_showShoot():void
	{
		UI.instance.getPanel(UIGame).show_shoot();
	}

	/**
	 * 显示飞行UI
	 */
	public net_showFly():void
	{
		UI.instance.getPanel(UIGame).show_fly();
	}

	/**
	 * 显示隐身UI
	 */
	public net_showHide():void
	{
		UI.instance.getPanel(UIGame).show_hide();
	}

	/**
	 * 显示隐身CD UI
	 */
	public net_hideCD():void
	{
		UI.instance.getPanel(UIGame).hideCD();
	}

	/**
	 * 显示飞行CD UI
	 */
	public net_flyCD():void
	{
		UI.instance.getPanel(UIGame).flyCD();
	}

}